package com.ufaud.ais.pub.dao.ibatis;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ufaud.ais.pub.dao.IGenericQryDao;
import com.ufaud.ais.pub.view.PageBean;

public class GenericQryDaoIBatis<T> extends SqlMapClientDaoSupport implements IGenericQryDao<T, Object> {

	@SuppressWarnings("unchecked")
	public List<T> findByNamedQuery(String queryName, Object paramObject) {
		return (List<T>) getSqlMapClientTemplate().queryForList(queryName, paramObject);
	}

	@SuppressWarnings("unchecked")
	public PageBean<T> findPageByNamedQuery(String queryName, Object paramObject, int pageIndex, int pageSize) {
		int totalCount = getSqlMapClientTemplate().queryForList(queryName, paramObject).size();
		List<T> resultList =  getSqlMapClientTemplate().queryForList(queryName, paramObject, PageBean.getOffset(pageIndex, pageSize), pageSize);
		return PageBean.getInstance(resultList, pageIndex, pageSize, totalCount);
	}

}